package client_commands;

import java.util.StringTokenizer;

import client.ClientApplication;
import client.ClientBindObject;
import client_tree.User;

public class SERV_UNBLOCKCommand extends Command {
	
	
	public SERV_UNBLOCKCommand(String parameter) {
		setCode(SERV_UNBLOCK);
		setParameter(parameter);
	}
	
	
	@Override
	public boolean executeCommand(ClientApplication theApp) {

		StringTokenizer tokens = new StringTokenizer(getParameter());
		
		String username = tokens.nextToken();

		User user = theApp.getClientModel().getOnlineModel().getUserByUsername(username);;

		if (user == null) {
			user = theApp.getClientModel().getOfflineModel().getUserByUsername(username);;
		}
		
		if (user == null) {
			return false;
		}

		theApp.getWindow().refreshTree();
		
		ClientBindObject cbo = ClientApplication.clientBinding.get(username);		
		
		if(cbo != null) {
			cbo.getDialog().setSendButtonRights(true);
		}
		
		return true;
	}

}
